package com.springaop.demo;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class Broker {
    //定义一个切入点和切入点表达式
    //什么时候?什么地方?
  /*  @Before("execution(* com.springaop.demo.Landlord.service())")
    public void before(){
        System.out.println("带租客看房");
        System.out.println("谈价格");
    }
    @AfterReturning("execution(* com.springaop.demo.Landlord.service())")
    public void afterReturning(){
        System.out.println("交钥匙");
    }
    @AfterThrowing("execution(* com.springaop.demo.Landlord.service())")
    public void afterThrowing(){
        System.out.println("沟通不愉快!!");
    }
    @After("execution(* com.springaop.demo.Landlord.service())")
    public void after(){
        System.out.println("不管你同不同意,必须租给我!!");
    }
*/

    /**
     * 环绕通知,可以取代以上所有通知.
     * @param joinPoint
     */
    //  在XX包下所有类的所有方法
    @Around("execution(* com.springaop.demo.*.*(..))")
//    @Around("execution(* com.springaop.demo.Landlord.service())")
    public void around(ProceedingJoinPoint joinPoint){
        try {
            System.out.println("带租客看房1111");
            System.out.println("谈价格111111");
           joinPoint.proceed();//放开往下走
            System.out.println("交钥匙111111");
        } catch (Throwable throwable) {
            System.out.println("沟通不愉快!!1111111");
            throwable.printStackTrace();
        }finally {
            System.out.println("不管你同不同意,必须租给我!! 1111 ");
        }
    }
}
